package com.pj.project4sp.sp_mqqt_log;

import com.pj.utils.cache.RedisUtil;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;



@Service
@Slf4j
public class SpMqqtLogService  {
	@Autowired
	SpMqqtLogMapper spMqqtLogMapper;

	public void getByDeviceType(){
		//每5分钟更新一次数据
		String key = "sp_mqqt_log_list_deviceType";
		long startTime = System.currentTimeMillis();
		//更新
		log.info("开始查询DeviceType");
		List<SpMqqtLog> clientIdNum = spMqqtLogMapper.getByDeviceType();
		List list =new ArrayList<>();
		for (SpMqqtLog spMqqtLog:clientIdNum) {
			if (!(spMqqtLog.getDeviceType()==null||spMqqtLog.getDeviceType().equals(""))){
				list.add(spMqqtLog);
			}
		}
		log.info("查询结束："+(System.currentTimeMillis()-startTime)+"毫秒");
		RedisUtil.forValueSet(key, list);
	}
	public void getMqqtLogList(){
		//每15分钟更新一次数据
		String key = "sp_mqqt_log_list";
		long startTime = System.currentTimeMillis();
		//更新
		log.info("开始查询List");
		List<SpMqqtLog> clientIdNum = spMqqtLogMapper.getByClientIdNum();
		if (clientIdNum.size() <= 0) {
			log.info("===== 无数据 =====");
			return;
		}
		log.info("查询结束："+(System.currentTimeMillis()-startTime)+"毫秒");
		RedisUtil.forValueSet(key, clientIdNum);
	}

	public void getMqqtLogListTime(){
		//每30分钟更新一次数据
		String key = "sp_mqqt_log_list_time";
		long startTime = System.currentTimeMillis();
		//更新
		log.info("开始查询ListTime");
		List<SpMqqtLog> clientIdNum = spMqqtLogMapper.getByClientId();
		if (clientIdNum.size() <= 0) {
			log.info("===== 无数据 =====");
			return;
		}
		log.info("查询结束："+(System.currentTimeMillis()-startTime)+"毫秒");
		RedisUtil.forValueSet(key, clientIdNum);
	}

}
